<?php
class CDbTableAr
{
	/**
	 * example:
	 * $attributes = Array (
	 *			'*','name','consult.consulttime' 
	 *	);
	 *
	 * csortAttributes($attributes);
	 * 
	 * result:
	 * Array(0 => '*', 1 => 'name','consult.consulttime' => array
     *  (
     *   'asc' => 'consult.consulttime asc'
     *   'desc' => 'consult.consulttime desc'
     *   'label' => 'consult.consulttime'
     *  ))
	 * @param array $columns
	 * @return array $attributes
	 */
	public function csortAttributes($columns)
	{
		$attributes = array ();
		foreach ( $columns as $column )
		{
			if (strpos ( $column, '*' ) !== false && strlen ( $column ) == 1)
			{
				array_push ( $attributes, $column );
			} elseif (strpos ( $column, '.' ) === false)
			{
				array_push ( $attributes, $column );
			} elseif (preg_match ( "/[a-z]+?\.[a-z]+$/i", $column ))
			{
				$attributes [$column] = array (
						'asc' => $column . ' asc','desc' => $column . ' desc','label' => $column 
				);
			}
		}
		return $attributes;
	}
}
?>
